﻿<sh:BasePage
    x:Name="pageRoot"
    x:Class="CorpStore.GroupDetailsPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="using:CorpStore"
    xmlns:vm="using:CorpStore.ViewModels"
    xmlns:common="using:CorpStore.Common"
    xmlns:sh="using:StoreHelper"
    RequestedTheme="Light"
    NavigationCacheMode="Enabled"
    Loaded="BasePage_Loaded"
    mc:Ignorable="d">

    <!-- set design time data context -->
    <Page.DataContext>
        <vm:FakeViewModel/>
    </Page.DataContext>

    <!-- Set of resources local to this page (CollectionViewSource, DataTemplates, etc.) -->
    <Page.Resources>
        <!-- Collection of items displayed by this page -->
        <CollectionViewSource
            x:Name="applicationsViewSource"
            Source="{Binding CurrentGroup.Applications}"
        />

        <!-- data template used for group headers on GroupDetailsPage -->
        <DataTemplate x:Key="GroupDetailsHeaderTemplate">
            <Grid Margin="0,0,0,2">
                <Button Foreground="{ThemeResource ApplicationHeaderForegroundThemeBrush}"
                                                    AutomationProperties.Name="Group Title"
                                                    Style="{StaticResource TextBlockButtonStyle}" >
                    <StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Name}" Foreground="{Binding Foreground, RelativeSource={RelativeSource Mode=TemplatedParent}}" Margin="0,-11,10,10" Style="{StaticResource SubheaderTextBlockStyle}" TextWrapping="NoWrap" />
                        </StackPanel>
                        <TextBlock Text="{Binding Description}" Foreground="{Binding Foreground, RelativeSource={RelativeSource Mode=TemplatedParent}}" Margin="0,-11,10,10" Style="{StaticResource SubheaderTextBlockStyle}" FontSize="12" TextWrapping="Wrap"/>
                    </StackPanel>
                </Button>
            </Grid>
        </DataTemplate>

    </Page.Resources>

    <Page.BottomAppBar>
        <CommandBar Background="Black" IsSticky="False">
            <AppBarButton Name="btnRefresh" Label="Refresh" Background="Green" Icon="Refresh" BorderBrush="Green" Click="btnRefresh_Click"/>
        </CommandBar>
    </Page.BottomAppBar>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}" >
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <!-- Row 0: Back button and page title -->
        <Grid x:Name="gridHeader" Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <AppBarButton x:Name="backButton" Grid.Column="0" VerticalAlignment="Center" Margin="39,59,39,0" Icon="Back" Foreground="Black" Style="{StaticResource NavigationBackButtonNormalStyle}"
                          Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}" />
            <TextBlock x:Name="pageTitle"  Grid.Column="1" Text="{Binding CurrentGroup.Name}" Style="{StaticResource HeaderTextBlockStyle}" 
                       IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Center" Margin="0,59,0,8"/>
            <Button Width="1"/>
            <SearchBox x:Name="searchBoxSuggestions" Grid.Column="2" Height="35" Margin="0,0,16,0"
                   HorizontalAlignment="Left" VerticalAlignment="Center" Width="250" SuggestionsRequested="SearchBoxEventsSuggestionsRequested" 
                   ResultSuggestionChosen="SearchBoxSuggestions_ResultSuggestionChosen" IsTabStop="False" PlaceholderText="Search Apps" SearchHistoryEnabled="False" FocusOnKeyboardInput="True"/>
            <TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="10,0,0,0" Text="{Binding CurrentGroup.Description}" Style="{StaticResource BodyTextBlockStyle}" TextWrapping="Wrap"/>
        </Grid>

        <!-- Row 1: Main content -->
        <Grid Grid.Row="1" Margin="120,0,0,0" x:Name="ContentGrid">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="79*"/>
                <ColumnDefinition Width="1167*"/>
            </Grid.ColumnDefinitions>
            <ProgressRing x:Name="progressRing" IsActive="{Binding ProgressIsActive}" Width="50" Height="50" Grid.Column="1" Margin="519.493,289,598,289"/>
            <GridView
                    x:Name="itemGridView"
                    AutomationProperties.AutomationId="ItemGridView"
                    AutomationProperties.Name="Grouped Items"
                    ItemsSource="{Binding CurrentGroup.Applications}"
                    SelectionMode="None"
                    IsItemClickEnabled="True"
                    ItemClick="ItemView_ItemClick" Grid.ColumnSpan="2" >

                <GridView.ItemTemplate>
                    <!-- Grid-appropriate 250 pixel square item template as seen in the GroupedItemsPage and ItemsPage -->
                    <DataTemplate>
                        <Grid HorizontalAlignment="Left" Width="200" Height="200">
                            <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}">
                                <Image Source="{Binding SplashScreenImage}" Stretch="Fill" AutomationProperties.Name="{Binding Name}">
                                </Image>
                            </Border>
                            <StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
                                <TextBlock Text="{Binding DisplayName}" Foreground="{ThemeResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource BaseTextBlockStyle}" Margin="15,0,15,0" FontWeight="SemiBold"/>
                                <TextBlock Text="{Binding ShortDescription}" Foreground="{ThemeResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource BaseTextBlockStyle}" TextWrapping="Wrap" Margin="15,0,15,10" FontSize="12"/>
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </GridView.ItemTemplate>
            </GridView>

            <!-- Vertical scrolling list only used when snapped -->
            <ListView
                x:Name="itemListView"
                AutomationProperties.AutomationId="ItemListView"
                AutomationProperties.Name="Grouped Items"
                Visibility="Collapsed"
                Margin="0,-10,0,0"
                Padding="10,0,0,60"
                ItemsSource="{Binding CurrentGroup.Applications}"
                SelectionMode="None"
                IsSwipeEnabled="false"
                IsItemClickEnabled="True"
                ItemClick="ItemView_ItemClick" Grid.ColumnSpan="2">

                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="6">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="60" Height="60">
                                <Image Source="{Binding SplashScreenImage}" Stretch="Fill"/>
                            </Border>
                            <StackPanel Grid.Column="1" Margin="8,0,0,0" Orientation="Horizontal">
                                <TextBlock Text="{Binding DisplayName}" Margin="0,-11,10,10" Style="{StaticResource SubheaderTextBlockStyle}" TextWrapping="NoWrap" />
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

        </Grid>

        <!-- main content grid -->
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState x:Name="Portrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="searchBoxSuggestions" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="FontSize">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="32"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

    </Grid>

    <!-- top level grid containing back button row and main content -->

</sh:BasePage>
